package com.guonl.open.api;


import com.guonl.open.api.client.RespDecoder;
import feign.codec.Decoder;
import feign.optionals.OptionalDecoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.cloud.openfeign.support.HttpMessageConverterCustomizer;
import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class WlhyOpenApiClientConfiguration extends FeignClientsConfiguration {

    @SuppressWarnings({"SpringJavaAutowiredFieldsWarningInspection"})
    @Autowired
    private ObjectFactory<HttpMessageConverters> messageConverters;

    @Bean("wlhyOpenApiFeignDecoder")
    public Decoder feignDecoder(ObjectProvider<HttpMessageConverterCustomizer> customizers) {
        return new OptionalDecoder(
            new ResponseEntityDecoder(
                new RespDecoder(
                    new SpringDecoder(messageConverters, customizers)
                )
            )
        );
    }

}
